package org.zxp.thread.communication.observation;

/**
 * @program: zxp-thread-test
 * @description: 消费者，不能挑选给啥要啥，暴力需求提供者
 * @author: X-Pacific zhang
 * @create: 2019-05-18 15:58
 **/
public class Consumer implements Runnable {
    int flag = 0;
    /**
     * 传入的flag越大，则生产的越慢
     * @param flag
     */
    public Consumer(int flag){
        this.flag = flag;
    }

    @Override
    public void run() {
        while(true){
            try {
                MidLock.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {
                Thread.sleep(flag);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
